/*     */ package com.umeng.fb.a;
/*     */ 
/*     */ import android.content.Context;
/*     */ import com.umeng.common.Log;
/*     */ import com.umeng.common.util.h;
/*     */ import com.umeng.fb.c.a;
/*     */ import com.umeng.fb.model.DevReply;
/*     */ import com.umeng.fb.model.Reply;
/*     */ import com.umeng.fb.model.Store;
/*     */ import com.umeng.fb.model.UserInfo;
/*     */ import com.umeng.fb.model.UserReply;
/*     */ import com.umeng.fb.model.UserTitleReply;
/*     */ import java.io.UnsupportedEncodingException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Random;
/*     */ import org.apache.http.HttpEntity;
/*     */ import org.apache.http.HttpRequest;
/*     */ import org.apache.http.HttpResponse;
/*     */ import org.apache.http.StatusLine;
/*     */ import org.apache.http.client.ClientProtocolException;
/*     */ import org.apache.http.client.HttpClient;
/*     */ import org.apache.http.client.entity.UrlEncodedFormEntity;
/*     */ import org.apache.http.client.methods.HttpGet;
/*     */ import org.apache.http.client.methods.HttpPost;
/*     */ import org.apache.http.client.methods.HttpUriRequest;
/*     */ import org.apache.http.conn.params.ConnManagerParams;
/*     */ import org.apache.http.impl.client.DefaultHttpClient;
/*     */ import org.apache.http.message.BasicNameValuePair;
/*     */ import org.apache.http.params.HttpConnectionParams;
/*     */ import org.apache.http.params.HttpParams;
/*     */ import org.apache.http.util.EntityUtils;
/*     */ import org.json.JSONArray;
/*     */ import org.json.JSONException;
/*     */ import org.json.JSONObject;
/*     */ 
/*     */ public class b
/*     */ {
/*  44 */   private static final String e = b.class.getName();
/*     */   private Context f;
/*     */   public static final String a = "http://feedback.umeng.com/feedback";
/*     */   public static final String b = "http://feedback.umeng.com/feedback/reply";
/*     */   public static final String c = "http://feedback.umeng.com/feedback/reply";
/*     */   public static final String d = "http://feedback.umeng.com/feedback/feedbacks";
/*     */   private static final int g = 30000;
/*     */ 
/*     */   public b(Context paramContext)
/*     */   {
/*  57 */     this.f = paramContext;
/*     */   }
/*     */ 
/*     */   public d a(c paramc)
/*     */   {
/*  68 */     int i = new Random().nextInt(1000);
/*  69 */     String str1 = paramc.f;
/*  70 */     String str2 = paramc.a;
/*  71 */     JSONObject localJSONObject = paramc.e;
/*     */ 
/*  73 */     if (!(paramc instanceof c)) {
/*  74 */       Log.b(e, 
/*  75 */         "request type error, request must be type of FbReportRequest");
/*  76 */       return null;
/*     */     }
/*     */ 
/*  79 */     if (str1.length() <= 1) {
/*  80 */       Log.b(e, i + ":\tInvalid baseUrl.");
/*  81 */       return null;
/*     */     }
/*     */ 
/*  85 */     Object localObject1 = null;
/*  86 */     if (str2 != null) {
/*  87 */       Log.a(e, i + ": post: " + str1 + " " + localJSONObject.toString());
/*     */ 
/*  89 */       localObject2 = new ArrayList(1);
/*  90 */       ((List)localObject2).add(new BasicNameValuePair(str2, localJSONObject.toString()));
/*     */ 
/*  92 */       localObject3 = null;
/*     */       try {
/*  94 */         localObject3 = new UrlEncodedFormEntity((List)localObject2, "UTF-8");
/*     */       } catch (UnsupportedEncodingException localUnsupportedEncodingException) {
/*  96 */         throw new AssertionError(localUnsupportedEncodingException);
/*     */       }
/*     */ 
/*  99 */       localObject1 = new HttpPost(str1);
/* 100 */       ((HttpRequest)localObject1).addHeader(((HttpEntity)localObject3).getContentType());
/* 101 */       ((HttpPost)localObject1).setEntity((HttpEntity)localObject3);
/*     */     } else {
/* 103 */       Log.a(e, i + ":\tget: " + str1);
/*     */ 
/* 105 */       localObject1 = new HttpGet(str1);
/*     */     }
/* 107 */     Object localObject2 = new DefaultHttpClient();
/* 108 */     Object localObject3 = ((HttpClient)localObject2).getParams();
/* 109 */     HttpConnectionParams.setConnectionTimeout((HttpParams)localObject3, 
/* 110 */       30000);
/* 111 */     HttpConnectionParams.setSoTimeout((HttpParams)localObject3, 30000);
/* 112 */     ConnManagerParams.setTimeout((HttpParams)localObject3, 30000L);
/*     */     try
/*     */     {
/* 116 */       HttpResponse localHttpResponse = ((HttpClient)localObject2).execute((HttpUriRequest)localObject1);
/*     */ 
/* 118 */       if (localHttpResponse.getStatusLine().getStatusCode() == 200) {
/* 119 */         HttpEntity localHttpEntity = localHttpResponse.getEntity();
/* 120 */         String str3 = EntityUtils.toString(localHttpEntity);
/*     */ 
/* 122 */         Log.a(e, "res :" + str3);
/* 123 */         return new d(new JSONObject(str3));
/*     */       }
/*     */     } catch (ClientProtocolException localClientProtocolException) {
/* 126 */       Log.c(e, 
/* 127 */         i + 
/* 128 */         ":\tClientProtocolException,Failed to send message." + 
/* 129 */         str1, localClientProtocolException);
/* 130 */       return null;
/*     */     } catch (Exception localException) {
/* 132 */       Log.c(e, i + ":\tIOException,Failed to send message." + str1, 
/* 133 */         localException);
/* 134 */       return null;
/*     */     }
/* 136 */     return null;
/*     */   }
/*     */ 
/*     */   public List<DevReply> a(List<String> paramList, String paramString1, String paramString2)
/*     */   {
/* 155 */     if ((paramList == null) || (paramList.size() == 0) || 
/* 156 */       (h.d(paramString2))) {
/* 157 */       return null;
/*     */     }
/*     */ 
/* 160 */     StringBuilder localStringBuilder = new StringBuilder();
/*     */ 
/* 162 */     for (Object localObject2 = paramList.iterator(); ((Iterator)localObject2).hasNext(); ) { localObject1 = (String)((Iterator)localObject2).next();
/* 163 */       if (!h.d((String)localObject1))
/*     */       {
/* 165 */         localStringBuilder.append((String)localObject1);
/* 166 */         localStringBuilder.append(",");
/*     */       } }
/* 168 */     if (localStringBuilder.length() > 1) {
/* 169 */       localStringBuilder.replace(localStringBuilder.length() - 1, localStringBuilder.length(), "");
/*     */     }
/*     */ 
/* 172 */     Object localObject1 = new StringBuilder("http://feedback.umeng.com/feedback/reply");
/* 173 */     ((StringBuilder)localObject1).append("?appkey=" + paramString2);
/* 174 */     ((StringBuilder)localObject1).append("&feedback_id=" + localStringBuilder);
/* 175 */     if (!h.d(paramString1))
/* 176 */       ((StringBuilder)localObject1).append("&startkey=" + paramString1);
/* 177 */     Log.c(e, "getDevReply url: " + localObject1);
/*     */ 
/* 179 */     localObject2 = new DefaultHttpClient();
/* 180 */     HttpParams localHttpParams = ((HttpClient)localObject2).getParams();
/* 181 */     HttpConnectionParams.setConnectionTimeout(localHttpParams, 
/* 182 */       30000);
/* 183 */     HttpConnectionParams.setSoTimeout(localHttpParams, 30000);
/* 184 */     ConnManagerParams.setTimeout(localHttpParams, 30000L);
/* 185 */     HttpGet localHttpGet = new HttpGet(((StringBuilder)localObject1).toString());
/*     */     try
/*     */     {
/* 189 */       HttpResponse localHttpResponse = ((HttpClient)localObject2).execute((HttpUriRequest)localHttpGet);
/*     */ 
/* 191 */       if (localHttpResponse.getStatusLine().getStatusCode() == 200) {
/* 192 */         HttpEntity localHttpEntity = localHttpResponse.getEntity();
/* 193 */         String str = EntityUtils.toString(localHttpEntity);
/* 194 */         Log.c(e, "getDevReply resp: " + str);
/*     */ 
/* 196 */         JSONArray localJSONArray1 = new JSONArray(str);
/* 197 */         ArrayList localArrayList = new ArrayList();
/* 198 */         for (int i = 0; i < localJSONArray1.length(); i++) {
/*     */           try {
/* 200 */             JSONArray localJSONArray2 = localJSONArray1.getJSONArray(i);
/* 201 */             for (int j = 0; j < localJSONArray2.length(); j++)
/*     */               try {
/* 203 */                 DevReply localDevReply = new DevReply(
/* 204 */                   localJSONArray2.getJSONObject(j));
/* 205 */                 localArrayList.add(localDevReply);
/*     */               } catch (JSONException localJSONException2) {
/* 207 */                 localJSONException2.printStackTrace();
/*     */               }
/*     */           }
/*     */           catch (JSONException localJSONException1) {
/* 211 */             localJSONException1.printStackTrace();
/*     */           }
/*     */         }
/* 214 */         return localArrayList;
/*     */       }
/*     */     } catch (Exception localException) {
/* 217 */       localException.printStackTrace();
/*     */     }
/* 219 */     return null;
/*     */   }
/*     */ 
/*     */   public boolean a(Reply paramReply) throws IllegalArgumentException
/*     */   {
/* 224 */     if (paramReply == null)
/* 225 */       return true;
/* 226 */     if ((paramReply instanceof UserReply))
/* 227 */       return a((UserReply)paramReply);
/* 228 */     if ((paramReply instanceof UserTitleReply)) {
/* 229 */       return a((UserTitleReply)paramReply);
/*     */     }
/* 231 */     throw new IllegalArgumentException("Illegal argument: " + 
/* 232 */       paramReply.getClass().getName() + ". reply must be " + 
/* 233 */       UserReply.class.getName() + " or " + 
/* 234 */       UserTitleReply.class.getName() + ".");
/*     */   }
/*     */ 
/*     */   private boolean a(UserReply paramUserReply)
/*     */   {
/*     */     try {
/* 240 */       JSONObject localJSONObject = paramUserReply.toJson();
/* 241 */       a(localJSONObject);
/*     */ 
/* 243 */       b(localJSONObject);
/*     */ 
/* 245 */       c localc = new c("reply", localJSONObject, 
/* 246 */         "http://feedback.umeng.com/feedback/reply");
/* 247 */       d locald = a(localc);
/* 248 */       if (locald != null)
/*     */       {
/* 250 */         if ("ok".equalsIgnoreCase(locald.a().get("state")
/* 250 */           .toString()))
/* 251 */           return true; 
/*     */       }
/*     */     } catch (Exception localException) { localException.printStackTrace(); }
/*     */ 
/* 255 */     return false;
/*     */   }
/*     */ 
/*     */   private boolean a(UserTitleReply paramUserTitleReply)
/*     */   {
/*     */     try {
/* 261 */       JSONObject localJSONObject = paramUserTitleReply.toJson();
/* 262 */       a(localJSONObject);
/* 263 */       b(localJSONObject);
/*     */ 
/* 265 */       c localc = new c("feedback", localJSONObject, 
/* 266 */         "http://feedback.umeng.com/feedback/feedbacks");
/* 267 */       d locald = a(localc);
/*     */ 
/* 269 */       if (locald != null)
/*     */       {
/* 271 */         if ("ok".equalsIgnoreCase(locald.a().get("state")
/* 271 */           .toString()))
/* 272 */           return true; 
/*     */       }
/*     */     } catch (Exception localException) { localException.printStackTrace(); }
/*     */ 
/* 276 */     return false;
/*     */   }
/*     */ 
/*     */   private void a(JSONObject paramJSONObject) {
/*     */     try {
/* 281 */       JSONObject localJSONObject = a.b(this.f);
/*     */ 
/* 283 */       Log.c(e, "addRequestHeader: " + localJSONObject.toString());
/* 284 */       Iterator localIterator = localJSONObject.keys();
/* 285 */       while (localIterator.hasNext()) {
/* 286 */         String str = (String)localIterator.next();
/*     */ 
/* 288 */         paramJSONObject.put(str, localJSONObject.get(str));
/*     */       }
/*     */     }
/*     */     catch (JSONException localJSONException)
/*     */     {
/* 293 */       localJSONException.printStackTrace();
/*     */     }
/*     */   }
/*     */ 
/*     */   private void b(JSONObject paramJSONObject) {
/*     */     try {
/* 299 */       long l1 = Store.getInstance(this.f)
/* 300 */         .getUserInfoLastSyncAt();
/* 301 */       long l2 = Store.getInstance(this.f)
/* 302 */         .getUserInfoLastUpdateAt();
/* 303 */       Log.c(e, "addUserInfoIfNotSynced: last_sync_at=" + l1 + 
/* 304 */         " last_update_at=" + l2);
/*     */ 
/* 307 */       if (l1 < l2) {
/* 308 */         JSONObject localJSONObject = Store.getInstance(this.f).getUserInfo()
/* 309 */           .toJson();
/* 310 */         paramJSONObject.put("userinfo", localJSONObject);
/*     */       }
/*     */     } catch (JSONException localJSONException) {
/* 313 */       localJSONException.printStackTrace();
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\umeng_sdk.jar
 * Qualified Name:     com.umeng.fb.a.b
 * JD-Core Version:    0.6.2
 */